package com.qk.controller;

import com.qk.anno.Log;
import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.Activitydto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;
    @GetMapping
    public Result listAll(Activitydto activitydto)
    {
        log.info("查询所有活动");
        PageResult<Activity> pageResult = activityService.listAll(activitydto);
        return Result.success(pageResult);
    }
    @Log
    @DeleteMapping("{id}")
    public Result delete(@PathVariable  Integer id)
    {
        log.info("删除活动");
        activityService.delete(id);
        return Result.success();
    }
    @Log
    @PostMapping
    public Result save(@RequestBody Activity activity)
    {
        log.info("保存活动");
        activityService.save(activity);
        return Result.success();
    }
    @GetMapping("{id}")
    public Result get(@PathVariable Integer id)
        {
            log.info("查询活动");
            Activity activity = activityService.get(id);
            return Result.success(activity);
        }
    @Log
    @PutMapping
    public Result update(@RequestBody Activity activity)
        {
            log.info("更新活动");
            activityService.update(activity);
            return Result.success();
        }
        @GetMapping("/list")
        public Result listByTypeAll()
            {
                log.info("查询活动");
                List<Activity> activityList= activityService.listByTypeAll();
                return Result.success(activityList);
        }
        @GetMapping("/type/{type}")
    public Result listByType(@PathVariable Integer type)
        {
            log.info("查询活动");
            List<Activity> activityList = activityService.listByType(type);
            return Result.success(activityList);
        }
}
